//
//  UIViewController+Extension.m
//  SYRJ
//
//  Created by cooptec on 2018/4/20.
//  Copyright © 2018年 Law. All rights reserved.
//

#import "UIViewController+Extension.h"

@implementation UIViewController (Extension)

#pragma mark -- 弹出框
- (void)showAlert:(NSString *)title Confirm:(void(^)(void))confirm;
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:title preferredStyle:UIAlertControllerStyleAlert];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        confirm();
        
    }]];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
    
    [self presentViewController:alert animated:YES completion:nil];
}
//只有确定按钮
- (void)showSureAlert:(NSString *)title Confirm:(void(^)(void))confirm
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:title preferredStyle:UIAlertControllerStyleAlert];
    
    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        confirm();
        
    }]];
    
    
    [self presentViewController:alert animated:YES completion:nil];
}

- (void)showAlert:(NSString *)title
          message:(NSString *)message
           titles:(NSArray *)titles
           colors:(NSArray *)colors
      cancelTitle:(NSString *)cancelTitle
          confirm:(void (^)(NSInteger index))confirmBlock {
//    UIAlertController *alertVC = [LYAlertView initWithSYTitle:title message:message titles:titles colors:colors cancelTitle:cancelTitle alertStyle:UIAlertControllerStyleAlert click:^(NSInteger index) {
//        confirmBlock (index);
//    }];
    UIAlertController *alertVC = [UIAlertController initwithTitle:title message:message titles:titles cancelTitile:cancelTitle buttonColors:colors itemSelect:^(NSInteger selectIndex) {
        confirmBlock(selectIndex);
    }];
    [self presentViewController:alertVC animated:YES completion:nil];
}

- (void)showSheet:(NSString *)title
          message:(NSString *)message
           titles:(NSArray *)titles
           colors:(NSArray *)colors
      cancelTitle:(NSString *)cancelTitle
          confirm:(void (^)(NSInteger index))confirmBlock {
//    UIAlertController *alertVC = [LYAlertView initWithSYTitle:title message:message titles:titles colors:colors cancelTitle:cancelTitle alertStyle:UIAlertControllerStyleActionSheet click:^(NSInteger index) {
//        confirmBlock (index);
//    }];
    UIAlertController *alertVC = [UIAlertController initwithTitle:title message:message titles:titles cancelTitle:cancelTitle itemSelect:^(NSInteger selectIndex) {
        confirmBlock (selectIndex);
    }];
    [self presentViewController:alertVC animated:YES completion:nil];
}

@end
